package cn.itsource.system.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.system.domain.TMenu;
import cn.itsource.system.query.OperationLogsQuery;
import cn.itsource.system.query.TMenuQuery;
import cn.itsource.system.service.OperationLogsService;
import cn.itsource.system.service.TMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/operationLogs")

public class OperationLogsController {
    @Autowired
    private OperationLogsService operationLogsService;


    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            operationLogsService.delete(id);
            return new AjaxResult().setSuccess(true).setMessage("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setSuccess(false).setMessage("删除失败");
        }
    }

    @PatchMapping("/patchDelete")
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        try {
            operationLogsService.patchDelete(ids);
            return new AjaxResult().setSuccess(true).setMessage("批量删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setSuccess(false).setMessage("批量删除失败");
        }
    }

    @PostMapping("/selectByQueryPage")
    public AjaxResult selectByPage(@RequestBody OperationLogsQuery operationLogsQuery)
    {
        try {
            return new AjaxResult().me().setResultObj(operationLogsService.selectByQueryPage(operationLogsQuery));
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setSuccess(false).setMessage("服务器异常");
        }
    }
}
